import router from '@system.router';
import prompt from '@system.prompt';
import http from '@ohos.net.http';
export default {
    data: {
        title: 'World',
        myOrder: [{
                      orderId: 0,
                      orderUserId: 0,
                      orderStatus: 0,
                      orderTime: "1",
                      orderPrice: 0,
                      orderItem: [{"itemImagePath":""}]
                  }
        ]
    },
    onjump(index) {
        router.push({
            uri: "pages/myorderdetail/myorderdetail",
            params: {
                commodity: this.myOrder[index].orderItem
            }
        })
    },
    onInit() {
        let httpRequest = http.createHttp();
        httpRequest.request(
        // 填写http请求的url地址，可以带参数也可以不带参数。URL地址需要开发者自定义。GET请求的参数可以在extraData中指定
        this.$app.$def.getOrderSearchUrl(),
            {
                method: 'GET',
                extraData: {
                    orderUserId: this.$app.$def.globalData.user.userId
                }
            }, (err, data) => {
            if (!err) {
                // data.result为http响应内容，可根据业务需要进行解析
                console.info('Result:' + data.result);
                console.log("--------->")
                this.$app.$def.globalData.jsonResult = JSON.parse(data.result);
                if(this.$app.$def.globalData.jsonResult.code == 1){
                    this.myOrder= this.$app.$def.globalData.jsonResult.info;
                    console.log(this.myOrder[0].orderItem[0].itemImagePath[0])
                }
                else{
                    this.msg = this.$app.$def.globalData.jsonResult.msg
                    prompt.showToast({
                        message: this.msg,
                        duration: 2000,
                    });
                }
                // data.header为http响应头，可根据业务需要进行解析
                console.info('header:' + data.header);
            } else {
                console.info('error:' + err.data);
            }
        }
        );
    },

}
